<?php

namespace app\common\model;

use think\Model;

class Region extends Model
{
    /**
     * getRegionDictById
     * @param array $id
     * @return array
     * @throws
     */
    public function getRegionDictById(array $id): array
    {
        $list = $this->where([['id', 'in', $id]])->select();
        $list = $list ? $list->toArray() : [];
        return array_dict($list, 'id');
    }

    /**
     * getSelectList
     * @return array
     * @throws
     */
    public function getSelectList(): array
    {
        $regions = $this->field('id,name')->select();
        $regions = $regions ? $regions->toArray() : [];
        array_unshift($regions, ['id' => '0', 'name' => '全部区域']);
        return $regions;
    }
}